package com.sc.servlet.user.field;

import com.alibaba.fastjson.JSONObject;
import com.sc.pojo.Field;
import com.sc.services.FieldServices;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @description: 选择预定该场地后通过异步请求用场地号获得场地名称
 * @author: sc
 * @create: 2023-01-04 16:01
 **/
@WebServlet("/getFieldName")
public class getFieldNameServlet extends HttpServlet {

    private FieldServices fieldServices = new FieldServices();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        String fieldid = request.getParameter("fieldid");
        Field field = fieldServices.selectFieldById(Integer.parseInt(fieldid));

        String jsonString = JSONObject.toJSONString(field.getFieldname());
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);



    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}